package com.gxa.modules.datamanagement.controller;

import com.gxa.common.utils.PageUtils;
import com.gxa.common.utils.Result;
import com.gxa.modules.datamanagement.entity.BasicInformation;
import com.gxa.modules.datamanagement.form.BasicInformationForm;
import com.gxa.modules.datamanagement.service.BasicInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

@Api(tags = "小区信息接口")
@RestController
@Slf4j
public class BasicInformationController {
    @Autowired
    private BasicInformationService basicInformationService;
    @ApiOperation(value="小区信息查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "page",value ="当前是第几页",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "limit",value ="每页显示多少条",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "cellName",value ="查询条件-小区名称",dataType ="String"),
    }
    )
    @GetMapping("/basicInformation/list")
    public Result<PageUtils> list(@RequestParam Map<String,Object> params){
        log.info("----params-----{}----",params);
        PageUtils pageUtils = this.basicInformationService.queryByPage(params);
        return new Result<PageUtils>().ok(pageUtils);
    }

    @ApiOperation(value="小区信息添加接口")
    @PostMapping("/basicInformation/add")
    public Result add(@RequestBody BasicInformationForm basicInformationForm){
        log.info("----body-----{}----",basicInformationForm);
        BasicInformation basicInformation = new BasicInformation(basicInformationForm);
        this.basicInformationService.save(basicInformation);
        return new Result().ok();
    }

    @ApiOperation(value="小区信息删除接口")
    @DeleteMapping ("/basicInformation/delete")
    public Result delete(@RequestParam List<Integer> ids){
        log.info("----param-----{}----",ids);
        this.basicInformationService.removeByIds(ids);
        return new Result().ok();
    }

    @ApiOperation(value="小区信息修改接口")
    @PutMapping ("/basicInformation/update")
    public Result update(@RequestBody BasicInformationForm basicInformationForm){
        log.info("----param-----{}----",basicInformationForm);
        BasicInformation basicInformation = new BasicInformation(basicInformationForm);
        this.basicInformationService.updateById(basicInformation);
        return new Result().ok();
    }

}
